package com.xm2.demo.system.echart.service;

import com.xm2.demo.system.echart.vo.Count;
import com.xm2.demo.system.echart.vo.Data;
import com.xm2.demo.system.order.dao.OrderRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Create
 * @create 2019-01-01 16:54
 * @Description：
 */
@Service
public class EchartService {

    @Autowired
    private OrderRepository orderRepository;

    public List<Count> echart(Data data) {

        int minMonth = Integer.parseInt(data.getMinMonth());
        int maxMonth = Integer.parseInt(data.getMaxMonth());
        List<Count> counts = new ArrayList<>();

        for(;minMonth<=maxMonth;minMonth++){
            Count count = new Count();
            count.setMonth(minMonth);
            String date;
            if (minMonth <10){
              date = data.getYear().concat("0"+minMonth);
            }else {
                date =data.getYear().concat(minMonth+"");
            }
            double money;
            try {
                if (data.getNumber().equals("总业绩")){
                    if (minMonth <10){
                        date = data.getYear().concat("-0"+minMonth);
                    }else {
                        date =data.getYear().concat("-"+minMonth);
                    }
                    money = orderRepository.sum(date);
                } else {
                    money = orderRepository.sum1(date);
                }

            } catch (Exception e) {
                money = 0.0;
            }
            count.setMonthIncome(money);
            counts.add(count);
        }
        return counts;
    }


}
